package com.imooc.security.user;

import lombok.Data;
import lombok.NoArgsConstructor;
import org.apache.commons.lang3.StringUtils;

import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.validation.constraints.NotBlank;


/**
 * @ClassName UserInfo
 * @Description TODO
 * @Author wushaopei
 * @Date 2020/10/17 13:22
 * @Version 1.0
 */
@Data
public class UserInfo {

    private Long id ;

    private String name;

    @NotBlank(message = "用户名不能为空")
    private String username;

    @NotBlank(message = "密码不能为空")
    private String password;
//    @NotBlank(message = "权限不能为空")
    private String permissions;

    /**
     * @Description TODO 根据请求的method来判断是否有访问当前接口的权限
     * @param method
     * @return
     */
    public boolean hasPermission(String method) {
        boolean result = false;
        // 判断该权限是读还是写
        if(StringUtils.equalsIgnoreCase("get",method)){
            result = StringUtils.contains(permissions, "r");
        }else {
            result = StringUtils.contains(permissions,"w");
        }
        return result;
    }
}
